package BandB.Tool.GPhoneManager.AppManager.Grid;

import BandB.Tool.GPhoneManager.ConfigManager;
import BandB.Tool.GPhoneManager.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class SettingDialog extends Dialog {

	private CheckBox checkBox;
	private Context mContext;
	private Button confirmButton;
	private Button cancelButton;
	private static final String dialogTitle = "Settings";
	public static boolean ENABLE_GRID_NOTI_BAR;
	private ConfigManager mConfigManager;

	public SettingDialog(Context context) {
		super(context);
		mContext = context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle(dialogTitle);
		setContentView(R.layout.setting_dialog);
		mConfigManager = ConfigManager.getInstance(mContext);
		checkBox = (CheckBox) findViewById(R.id.setting_checkbox);
		ENABLE_GRID_NOTI_BAR = mConfigManager.getGridNotiBarEnabled();
		checkBox.setChecked(ENABLE_GRID_NOTI_BAR);

		confirmButton = (Button) findViewById(R.id.confirm_button);
		confirmButton.setOnClickListener(confirmClickListener);
		cancelButton = (Button) findViewById(R.id.cancel_button);
		cancelButton.setOnClickListener(cancelClickListener);

	}

	android.view.View.OnClickListener confirmClickListener = new android.view.View.OnClickListener() {

		@Override
		public void onClick(View v) {

			// settingConfig.setNotificationSetting(checkBox.isChecked());
			boolean newChecked = checkBox.isChecked();
			if (newChecked != ENABLE_GRID_NOTI_BAR) {
				mConfigManager.setGridBarEnabled(newChecked);
				if (newChecked) {
					((UninstallerGrid) mContext).showUninstallNotify();
				} else {
					((UninstallerGrid) mContext).cancelNotify();
				}
			}
			dismiss();
		}

	};
	android.view.View.OnClickListener cancelClickListener = new android.view.View.OnClickListener() {

		@Override
		public void onClick(View v) {
			// if (settingConfig.getNotificationSetting()) {
			// ((UninstallerGrid) mContext).showUninstallNotify();
			// } else {
			// ((UninstallerGrid) mContext).cancelNotify();
			// }
			dismiss();
		}

	};

}
